﻿<!--
	========================================================================
	 NQ Software Development Kit Component
	
	 Homepage: http://www.awzhome.de/
	========================================================================
	
	This Source Code Form is subject to the terms of the Mozilla Public
	License, v. 2.0. If a copy of the MPL was not distributed with this
	file, You can obtain one at http://mozilla.org/MPL/2.0/.
   
	The Original Code is code of NQ Software Development Kit Component.

	The Initial Developer of the Original Code is Andreas Weizel.
	Portions created by the Initial Developer are
	Copyright (C) 2012 Andreas Weizel. All Rights Reserved.
	
	Contributor(s): (none)
	
	========================================================================
-->

<UserControl
	x:Class="AWZhome.NQsdk.Visual.BarItemBrowserView"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
	xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
	xmlns:nqcs="clr-namespace:AWZhome.NQ.CommonServices;assembly=NQCommServ.Interface"
	xmlns:nqsdkhelpers="clr-namespace:AWZhome.NQsdk.Helpers"
	xmlns:nqsdkvisual="clr-namespace:AWZhome.NQsdk.Visual">

	<UserControl.Resources>
		<!-- DataTemplate for band items -->
		<CollectionViewSource x:Key="BarBandSortedDataSource" Source="{Binding Bands}">
			<CollectionViewSource.SortDescriptions>
				<scm:SortDescription PropertyName="IsNamedBand" Direction="Ascending" />
				<scm:SortDescription PropertyName="Name" Direction="Ascending" />
			</CollectionViewSource.SortDescriptions>
		</CollectionViewSource>

		<Style x:Key="ItemKeyTextStyle" TargetType="{x:Type TextBlock}">
			<Setter Property="Foreground" Value="DarkBlue" />
			<Style.Triggers>
				<!-- Setting a readable color for selected items -->
				<MultiDataTrigger>
					<MultiDataTrigger.Conditions>
						<Condition Binding="{Binding
							RelativeSource=
							{
								RelativeSource
								Mode=FindAncestor,
								AncestorType={x:Type TreeViewItem}
							},
							Path=IsSelected}"
						   Value="True" />
						<Condition Binding="{Binding ElementName=BarItemTreeView, Path=IsKeyboardFocusWithin}" Value="True" />
					</MultiDataTrigger.Conditions>
					<Setter Property="Foreground" Value="{x:Static SystemColors.HighlightTextBrush}" />
				</MultiDataTrigger>
			</Style.Triggers>
		</Style>

		<!-- Bar band type text style -->
		<Style x:Key="BarBandTypeStyle" TargetType="{x:Type TextBlock}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding BandObject.BandType}" Value="ToolBand">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.BandType.ToolBand}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding BandObject.BandType}" Value="MenuBand">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.BandType.MenuBand}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding BandObject.BandType}" Value="ContextMenu">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.BandType.ContextMenu}" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<!-- Bar item type text style -->
		<Style x:Key="BarItemTypeStyle" TargetType="{x:Type TextBlock}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding ItemObject.ItemType}" Value="Button">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.ItemType.Button}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding ItemObject.ItemType}" Value="CheckBox">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.ItemType.CheckBox}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding ItemObject.ItemType}" Value="RadioButton">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.ItemType.RadioButton}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding ItemObject.ItemType}" Value="Separator">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.ItemType.Separator}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding ItemObject.ItemType}" Value="MenuItem">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.ItemType.MenuItem}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding ItemObject.ItemType}" Value="SplitButton">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.ItemType.SplitButton}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding ItemObject.ItemType}" Value="DropDownButton">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.ItemType.DropDownButton}" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<!-- Data template for the "This container" root item -->
		<HierarchicalDataTemplate DataType="{x:Type nqsdkhelpers:ThisContainerTreeItem}"
										  ItemsSource="{Binding Source={StaticResource BarBandSortedDataSource}}">
			<Grid Margin="1,1,1,1">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="20" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<Image Grid.Column="0" Height="16" Width="16" />
				<TextBlock Grid.Column="1" Text="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.ThisContainer}" />
			</Grid>
		</HierarchicalDataTemplate>

		<!-- Data template for bands -->
		<HierarchicalDataTemplate DataType="{x:Type nqsdkhelpers:BarBandTreeItem}"
										  ItemsSource="{Binding BarItems}">
			<Grid Margin="1,1,1,1">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="20" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
				</Grid.ColumnDefinitions>
				<Image Grid.Column="0" Height="16" Width="16" />
				<TextBlock Grid.Column="1">
					<TextBlock.Style>
						<Style TargetType="{x:Type TextBlock}">
							<Style.Triggers>
								<DataTrigger Binding="{Binding IsNamedBand}" Value="True">
									<Setter Property="Text" Value="'" />
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</TextBlock.Style>
				</TextBlock>
				<TextBlock Grid.Column="2">
					<TextBlock.Style>
						<Style TargetType="{x:Type TextBlock}">
							<Style.Triggers>
								<DataTrigger Binding="{Binding IsNamedBand}" Value="False">
									<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.AllItems}" />
								</DataTrigger>
								<DataTrigger Binding="{Binding IsNamedBand}" Value="True">
									<Setter Property="Text" Value="{Binding BandObject.DisplayName}" />
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</TextBlock.Style>
				</TextBlock>
				<TextBlock Grid.Column="3">
					<TextBlock.Style>
						<Style TargetType="{x:Type TextBlock}">
							<Style.Triggers>
								<DataTrigger Binding="{Binding IsNamedBand}" Value="True">
									<Setter Property="Text" Value="'" />
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</TextBlock.Style>
				</TextBlock>
				<TextBlock Grid.Column="4">
					<TextBlock.Style>
						<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource ItemKeyTextStyle}">
							<Style.Triggers>
								<DataTrigger Binding="{Binding IsNamedBand}" Value="True">
									<Setter Property="Text" Value=" [" />
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</TextBlock.Style>
				</TextBlock>
				<TextBlock Grid.Column="5">
					<TextBlock.Style>
						<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource ItemKeyTextStyle}">
							<Style.Triggers>
								<DataTrigger Binding="{Binding IsNamedBand}" Value="True">
									<Setter Property="Text" Value="{Binding Name}" />
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</TextBlock.Style>
				</TextBlock>
				<TextBlock Grid.Column="6">
					<TextBlock.Style>
						<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource ItemKeyTextStyle}">
							<Style.Triggers>
								<DataTrigger Binding="{Binding IsNamedBand}" Value="True">
									<Setter Property="Text" Value="]" />
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</TextBlock.Style>
				</TextBlock>
			</Grid>
		</HierarchicalDataTemplate>

		<!-- Data template for bar items -->
		<HierarchicalDataTemplate DataType="{x:Type nqsdkhelpers:BarItemTreeItem}"
										  ItemsSource="{Binding BarItems}">
			<Grid Margin="1,1,1,1">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="20" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
				</Grid.ColumnDefinitions>
				<Image Grid.Column="0" Height="16" Width="16" Source="{Binding ItemObject.ItemImage}" />
				<TextBlock Grid.Column="1" Text="'" />
				<TextBlock Grid.Column="2" Text="{Binding DisplayName}" />
				<TextBlock Grid.Column="3" Text="'" />
				<TextBlock Grid.Column="4" Text=" ["
						   Style="{Binding Source={StaticResource ItemKeyTextStyle}}"/>
				<TextBlock Grid.Column="5" Text="{Binding Name}"
						   Style="{Binding Source={StaticResource ItemKeyTextStyle}}" />
				<TextBlock Grid.Column="6" Text="]"
						   Style="{Binding Source={StaticResource ItemKeyTextStyle}}" />
			</Grid>
		</HierarchicalDataTemplate>
	</UserControl.Resources>

	<Grid Name="InnerTreeGrid" Margin="0,0,0,0" >
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*" />
			<ColumnDefinition Width="200" />
		</Grid.ColumnDefinitions>

		<!-- TreeView for bands and bar items -->
		<TreeView Grid.Column="0" Name="BarItemTreeView" ItemsSource="{Binding}" Margin="0,0,5,0" />

		<GridSplitter Name="HorizGridSplitter" Width="5" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Stretch" />

		<Grid Grid.Column="1" Name="thisContainerPropertiesGrid" Visibility="Hidden" Background="{x:Static SystemColors.ControlBrush}">
			<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" TextWrapping="Wrap"
					   Text="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.ThisContainerProperties}" />
		</Grid>

		<Grid Grid.Column="1" Name="barBandPropertiesGrid" Visibility="Hidden" Background="{x:Static SystemColors.ControlBrush}">
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition />
			</Grid.RowDefinitions>

			<!-- Bold title with bar band key -->
			<TextBox Grid.Row="0" Text="{Binding Path=Name, Mode=OneWay}" IsReadOnly="True" FontWeight="Bold" BorderThickness="0"
					 Background="{x:Static SystemColors.ControlBrush}" FontSize="14" />
			<!-- Type of the band (menu bar, tool bar, context menu etc.) -->
			<TextBlock Grid.Row="1" Style="{Binding Source={StaticResource BarBandTypeStyle}}"
					 Background="{x:Static SystemColors.ControlBrush}" Margin="5,0,5,0" />
			<!-- Display name of the bar band -->
			<Grid Grid.Row="2" Margin="5,16,5,0">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
				</Grid.ColumnDefinitions>
				<TextBlock Grid.Column="0" Text="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.BandDisplayName}" Margin="0,0,10,0" />
				<TextBox Grid.Column="1" Text="{Binding Path=BandObject.DisplayName, Mode=OneWay}" IsReadOnly="True" BorderThickness="0"
						 Background="{x:Static SystemColors.ControlBrush}" />
			</Grid>
		</Grid>

		<Grid Grid.Column="1" Name="barItemPropertiesGrid" Background="{x:Static SystemColors.ControlBrush}">
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition />
			</Grid.RowDefinitions>

			<!-- Bold title with bar item key -->
			<TextBox Grid.Row="0" Text="{Binding Path=Name, Mode=OneWay}" IsReadOnly="True" FontWeight="Bold" BorderThickness="0"
					 Background="{x:Static SystemColors.ControlBrush}" FontSize="14" />
			<!-- Type of the item (button, menu item, separator etc.) -->
			<TextBlock Grid.Row="1" Style="{Binding Source={StaticResource BarItemTypeStyle}}"
					 Background="{x:Static SystemColors.ControlBrush}" Margin="5,0,5,0" />

			<Grid Grid.Row="2" Margin="5,16,5,0">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
				</Grid.ColumnDefinitions>
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
				</Grid.RowDefinitions>

				<!-- Item content: Icon and/or text -->
				<TextBlock Grid.Row="0" Grid.Column="0" Text="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.Content}" Margin="0,0,10,0" />
				<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
					<Image Height="16" Source="{Binding ItemObject.ItemImage}" />
					<TextBox Text="{Binding Path=ItemObject.ItemText, Mode=OneWay}" IsReadOnly="True" BorderThickness="0"
						 Background="{x:Static SystemColors.ControlBrush}" />
				</StackPanel>

				<!-- Item tooltip -->
				<TextBlock Grid.Row="1" Grid.Column="0" Text="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.Tooltip}" Margin="0,0,10,0" />
				<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=ItemObject.ItemToolTip, Mode=OneWay}" IsReadOnly="True" BorderThickness="0"
						 Background="{x:Static SystemColors.ControlBrush}" />

				<!-- Item key shortcut (for menu items) -->
				<TextBlock Grid.Row="2" Grid.Column="0" Text="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.Shortcut}" Margin="0,0,10,0" />
				<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=ItemObject.Keys, Mode=OneWay}" IsReadOnly="True" BorderThickness="0"
						 Background="{x:Static SystemColors.ControlBrush}" />

				<!-- Item is enabled? -->
				<TextBlock Grid.Row="3" Grid.Column="0" Text="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.Enabled}" Margin="0,0,10,0" />
				<CheckBox Grid.Row="3" Grid.Column="1" IsEnabled="False" IsChecked="{Binding Path=ItemObject.ItemEnabled}" />

				<!-- Item is checked? -->
				<TextBlock Grid.Row="4" Grid.Column="0" Text="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.Checked}" Margin="0,0,10,0" />
				<CheckBox Grid.Row="4" Grid.Column="1" IsEnabled="False" IsChecked="{Binding Path=IsChecked, Mode=OneWay}" />
			</Grid>

			<!-- Item dependencies -->
			<!--<TextBlock Grid.Row="3" Background="{x:Static SystemColors.ControlBrush}" Margin="5,16,5,0"
					   Text="{nqcs:ResourceBinding Component=NQsdk, Name=BarItemBrowserView.Dependencies}"/>
			<ListView Grid.Row="4" Margin="5,0,5,0" ItemsSource="{Binding SessionDependencies}">
				
			</ListView>-->
		</Grid>
	</Grid>
</UserControl>
